import Vue from 'vue'
import VueRouter from 'vue-router'

let moduleFn = require.context('./routes',false,/\.js$/)
let routes = moduleFn.keys().reduce((p,c)=>{
  let m = moduleFn(c).default
  if(m){
    if(Array.isArray(m)){
      p = p.concat(m)
    }else{
      p.push(m)
    }
  }
  return p
},[])


Vue.use(VueRouter)
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
